package com.example.sxmall.intercepter;

import com.example.sxmall.dao.pojo.Admins;
import com.example.sxmall.dao.pojo.Users;
import com.example.sxmall.service.UsersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UsersDetailServiceImpl implements UserDetailsService {
    @Autowired
    UsersService usersService;

    /*用户登陆*/
    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {

        Users users = usersService.getByUsersName(username);
        if (users == null) {
            throw new UsernameNotFoundException("用户名或密码不正确");
        }
        return new AccountUsers(users.getUid(), users.getUaccount(), users.getUpwd(), getUsersAuthority(users.getUid()));
    }

    public List<GrantedAuthority> getUsersAuthority(Integer usersId){
        return null;
    }

}
